import Validate from '/utils/validate';
import PageModel from '/utils/pagemodel';
let validateForm = new Validate();
let pagemodel = new PageModel();
const app = getApp();

Page({
  data: {
    
  },
  onLoad(query) {
    let carInfo = my.getStorageSync({ key: "carInfo" }).data;
    if(carInfo.orderNo===null){
      //console.log('订单号未被缓存')
    }
    //查询订单
    my.httpRequest({
      url: app.queryOrderDetail_url,
      data:{
        order: carInfo.orderNo,
      },
      method: 'GET',
      success: (res) => {
        //console.log('订单详情返回：')
        //console.log(res)
        var status = res.data.data.status;
        var orderStatus = '';
        if(status==='0'){
          orderStatus = '等待确认'
        }else if(status==='1'){
          orderStatus = '支付成功'
        }else if(status==='2'){
          orderStatus = '支付异常'
        }else if(status==='16'){
          orderStatus = '办理中'
        }
        this.setData({
          orderStatus: orderStatus,
          orderNo: res.data.data.order,
          orderTime: res.data.data.create_time,
          carNum: res.data.data.car_num,
          payTotal: res.data.data.order_amount,
        })
      },
      fail: function(res) {
        //console.log({content: '订单查询失败'});
      },
      complete: function(res) {
        
      }
    })
    
  },
  onUnload() {
    // 关闭程序
  },
  goToDetailPage() {
    my.navigateTo({
      url: '/page/check-order-detail/check-order-detail?orderNo='+this.data.orderNo
    })
  },
  goToMyOrderPage(e) {
    const { url, openType = 'navigateTo' } = e.target.dataset;
    my[openType]({ url }); 
  },
  goToHomePage() {
    my.switchTab({
      url: '/page/check-orderOnline/index',
    })
  }
});

